<?php

namespace app\store\validate;

use think\Validate;

class GroupActivityValidate extends Validate
{
    protected $rule = [
        'store_id' => 'integer',
        'activity_title' => 'require|max:100',
        'activity_cover' => 'require|max:255',
        'start_time' => 'require|dateFormat:Y-m-d H:i:s',
        'end_time' => 'require|dateFormat:Y-m-d H:i:s',
        'rule_content' => 'require',
        'success_rule' => 'require',
        'fail_rule' => 'require',
        'prepayment_amount' => 'require|float|egt:0',
        'group_num' => 'checkGroupNum',
        'win_num' => 'require|gt:0',
        'resell_rate' => 'gt:0|between:0,100',
        'transfer_people_num' => 'gt:0',
        'transfer_times' => 'gt:0',
        'resell_time' => 'gt:0',
        'status' => 'in:0,1'
    ];

    protected $message = [
        'id.require' => '非法请求',
        'id.integer' => '非法请求',
        'activity_title.require' => '活动标题不能为空!',
        'activity_title.max' => '活动标题做多50个字符!',
        'activity_cover.require' => '请上传活动封面!',
        'start_time.require' => '请选择活动开始时间!',
        'start_time.dateFormat' => '开始时间不是有效的日期',
        'end_time.require' => '请选择活动结束时间!',
        'end_time.dateFormat' => '结束时间不是有效的日期',
        'rule_content.require' => '请输入活动规则!',
        'prepayment_amount.require' => '请输入预付金额',
        'prepayment_amount.float' => '预付金额只能是数字',
        'prepayment_amount.egt' => '预付金额必须大于等于0',
        'win_num.gt' => '中奖人数必须大于0',
        'resell_rate.gt' => '转手价格折率必须大于0',
        'resell_rate.between' => '转手价格折率必须在0-100之间',
        'transfer_people_num:gt' => '转手开团人数必须大于0',
        'transfer_times.gt' => '转手次数必须大于0',
        'resell_time.gt' => '单次转手时间必须大于0',
        'status.in' => '无效的状态值!'
    ];


    public function sceneEdit()
    {
    	return $this->only(['store_id','activity_title','activity_cover','start_time','end_time','rule_content',
                    'prepayment_amount','group_num','win_num','resell_rate','transfer_people_num','transfer_times','resell_time','status'])
                    ->append('id', 'require|integer');
    }

    public function checkGroupNum($value)
    {
        if ($value == -1 || $value>0){
            return true;
        }

        return  '拼团人数必须大于0或等于-1';
    }
}